package com.tp.ssm.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.tp.ssm.controller.exception.CustomException;
import com.tp.ssm.mapper.ItemsMapper;
import com.tp.ssm.mapper.ItemsMapperCustom;
import com.tp.ssm.po.Items;
import com.tp.ssm.po.ItemsCustom;
import com.tp.ssm.po.ItemsQueryVo;
import com.tp.ssm.service.ItemsService;

public class ItemsServiceImpl implements ItemsService {
	
	private ItemsMapper itemsMapper ;
	
	public ItemsMapper getItemsMapper() {
		return itemsMapper;
	}
	
	@Autowired
	public void setItemsMapper(ItemsMapper itemsMapper) {
		this.itemsMapper = itemsMapper;
	}

	private ItemsMapperCustom itemsMapperCustom ;
	
	public ItemsMapperCustom getItemsMapperCustom() {
		return itemsMapperCustom;
	}
	
	@Autowired
	public void setItemsMapperCustom(ItemsMapperCustom itemsMapperCustom) {
		this.itemsMapperCustom = itemsMapperCustom;
	}

	@Override
	public List<ItemsCustom> findItemsList(ItemsQueryVo vo) throws Exception {
		List<ItemsCustom> list = itemsMapperCustom.findItemsList(vo);
		return list;
	}

	@Override
	public ItemsCustom findById(Integer id) throws Exception {
		Items items = itemsMapper.selectByPrimaryKey(id);
		
		ItemsCustom itemsCustom = null ;
		if(items != null){
			itemsCustom = new ItemsCustom() ;
			BeanUtils.copyProperties(items, itemsCustom);
		}else{
			throw new CustomException("商品信息不存在") ;
		}
		return itemsCustom;
	}

	@Override
	public void updateItems(Integer id, ItemsCustom itemsCustom)
			throws Exception {
		
		itemsCustom.setId(id);
		itemsMapper.updateByPrimaryKeySelective(itemsCustom) ;
	}

}
